package Card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {
    public static String[] SUITS = {"♠", "♥", "♣", "♦"};

    //创建牌组
    public static List<Card> createCard() {
        List<Card> cardList = new ArrayList<>();
        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 0; j < 13; j++) {
                Card card = new Card(SUITS[i], j);
                cardList.add(card);
            }
        }
        return cardList;
    }

    //洗牌
    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size() - 1; i > 0; i--) {
            int randIdex = random.nextInt(i);
            Swap(cardList, i, randIdex);
        }
    }

    public void Swap(List<Card> cardList, int i, int j) {
            Card set = cardList.get(i);
            cardList.set(i,cardList.get(j));
            cardList.set(j,set);
    }
    //抓牌
    public List<List<Card>> paly (List<Card> cardList){
        List<List<Card>> hand = new ArrayList<>();

        List<Card> list0 = new ArrayList<>();
        List<Card> list1 = new ArrayList<>();
        List<Card> list2 = new ArrayList<>();

        hand.add(list0);
        hand.add(list1);
        hand.add(list2);

        for (int i = 0; i <5; i++) {
            for (int j = 0; j <3; j++) {
                Card tmp = cardList.remove(0);
                hand.get(j).add(tmp);
            }
        }
        return hand;
    }



























    /*public static String[] SUITS = {"♠", "♥", "♣", "♦"};

    public static List<Card> buyCard() { // 为什么使用static静态方法
        List<Card> cardList = new ArrayList<>();

        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 0; j < 13; j++) {
                Card card = new Card(SUITS[i], j);
                cardList.add(card);
            }
        }
        return cardList;
    }

    public void shuffle(List<Card> cardList) {
        Random random = new Random();

        //为什么需要从后往前循环
        for (int i = cardList.size() - 1; i > 0; i--) {
            int ranindex = random.nextInt(i);
            Swap(cardList, i, ranindex);
        }
    }


    public void Swap(List<Card> cardList, int i, int j) {
        Card tmp = cardList.get(i); // 为什么不是List<Card> tmp = cardList.get(i);
        cardList.set(i, cardList.get(j)); //为什么不是cardList.set(cardList.get(i), cardList.get(j));
        cardList.set(j, tmp);
    }

    public List<List<Card>> play(List<Card> cardList) {
        List<List<Card>> hand = new ArrayList<>();

        List<Card> card0 = new ArrayList<>();
        List<Card> card1 = new ArrayList<>();
        List<Card> card2 = new ArrayList<>();

        hand.add(card0);
        hand.add(card1);
        hand.add(card2);

        for (int i = 0; i <5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);//这部分是什么意思？
                hand.get(j).add(card);
            }
        }
        return hand;
    }*/


}